class Solution
{
public:
    bool searchMatrix(vector<vector<int>> &matrix, int target)
    {
        for (auto &row : matrix)
        {
            if (row[0] < target && binary_search(row.begin(), row.end(), target))
            {
                return true;
            }
            if (row[0] == target)
            {
                return true;
            }
            if (row[0] > target)
            {
                return false;
            }
        }
        return false;
    }
};